<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>fluidEngine</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="fluidControl.html" title="fluidControl" />
    <link rel="next" href="fluidLoad.html" title="fluidLoad" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">fluidEngine</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="fluidControl.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="fluidLoad.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="fluidEngine"></a>
      <div class="titlepage"></div>
      <a id="IndexFluidEngine" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">fluidEngine</span>
        </h2>
        <p>fluidEngine — 
      Instantiates a fluidsynth engine.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp108705744"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">ienginenum <span class="command"><strong>fluidEngine</strong></span> [iReverbEnabled] [, iChorusEnabled] [,iNumChannels] [, iPolyphony] </pre>
      </div>
      <div class="refsect1">
        <a id="idp108707776"></a>
        <h2>Description</h2>
        <p>Instantiates a fluidsynth engine, and returns <span class="emphasis"><em>ienginenum</em></span> to identify the
    engine. <span class="emphasis"><em>ienginenum</em></span> is passed to other other opcodes for loading 
    and playing SoundFonts and gathering the generated sound.  
    </p>
      </div>
      <div class="refsect1">
        <a id="idp108710032"></a>
        <h2>Initialization</h2>
        <p><span class="emphasis"><em>ienginenum </em></span> -- engine number assigned from fluidEngine.</p>
        <p><span class="emphasis"><em>iReverbEnabled </em></span> -- optionally set to 0 to disable any reverb effect in the loaded SoundFonts.</p>
        <p><span class="emphasis"><em>iChorusEnabled </em></span> -- optionally set to 0 to disable any chorus effect in the loaded SoundFonts.</p>
        <p><span class="emphasis"><em>iNumChannels </em></span> -- number of channels to use; range is 16-256 and Csound default is 256 (Fluidsynth's default is 16).</p>
        <p><span class="emphasis"><em>iPolyphony </em></span> -- number of voices to be played in parallel; range is 16-4096 and Csound default is 4096 (Fluidsynth's default is 256).
    Note: this is not the number of notes played at the same time as a single note may use create multiple voices depending on instrument zones
    and velocity/key of played note. 
    </p>
      </div>
      <div class="refsect1">
        <a id="idp108714880"></a>
        <h2>Examples</h2>
        <p>
      Here is example of the fluidsynth opcodes using 2 engines. It uses the file <a class="ulink" href="examples/fluidEngine.csd" target="_top"><em class="citetitle">fluidEngine.csd</em></a> and <a class="ulink" href="examples/midichn_advanced.mid" target="_top"><em class="citetitle">midichn_advanced.mid</em></a>.
    </p>
        <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac  -F  midichn_advanced.mid <span class="comment">;;;reatime audio out and midifile in</span>
<span class="comment">;-iadc    ;;;uncomment -iadc if realtime audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o fluidEngine.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32  
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span>  <span class="op">=</span> 1

<span class="comment">; LOAD SOUNDFONTS</span>
gienginenum1	<span class="opc">fluidEngine</span>
gienginenum2	<span class="opc">fluidEngine</span>
isfnum1	<span class="opc">fluidLoad</span> "sf_GMbank.sf2", gienginenum1, 1
                <span class="comment">; Piano 2, program 1, channel 1</span>
		<span class="opc">fluidProgramSelect</span>	gienginenum1, 1, isfnum1, 0, 1
                <span class="comment">; Piano 3, program 2, channel 2</span>
		<span class="opc">fluidProgramSelect</span>	gienginenum1, 2, isfnum1, 0, 2
isfnum2	<span class="opc">fluidLoad</span> "19Trumpet.sf2", gienginenum2, 1
                <span class="comment">; Trumpet, program 56, channel 3</span>
		<span class="opc">fluidProgramSelect</span>	gienginenum2, 3, isfnum2, 0, 56

<span class="comment">;Look for midifile in folder manual/examples</span>
<span class="comment">;"midichn_advanced.mid" sends notes to the soundfonts</span>

<span class="oblock">instr</span> 1 <span class="comment">; GM soundfont</span>
  <span class="comment">; INITIALIZATION</span>
	<span class="opc">mididefault</span>	60, p3 <span class="comment">; Default duration of 60 -- overridden by score.</span>
	<span class="opc">midinoteonkey</span>	p4, p5 <span class="comment">; Channels MIDI input to pfields.</span>
  <span class="comment">; Use channel assigned in fluidload.</span>
  ichannel   <span class="op">=</span> 1
  ikey       <span class="op">=</span> p4
  ivelocity  <span class="op">=</span> p5
	<span class="opc">fluidNote</span> gienginenum1, ichannel, ikey, ivelocity
<span class="oblock">endin</span>

<span class="oblock">instr</span> 2 <span class="comment">; GM soundfont</span>
  <span class="comment">; INITIALIZATION</span>
         <span class="opc">mididefault</span>   60, p3 <span class="comment">; Default duration of 60 -- overridden by score.</span>
         <span class="opc">midinoteonkey</span> p4, p5 <span class="comment">; Channels MIDI input to pfields.</span>
  <span class="comment">; Use channel assigned in fluidload.</span>
  ichannel   <span class="op">=</span> 2
  ikey       <span class="op">=</span> p4
  ivelocity  <span class="op">=</span> p5
         <span class="opc">fluidNote</span> gienginenum1, ichannel, ikey, ivelocity
<span class="oblock">endin</span>

<span class="oblock">instr</span> 3 <span class="comment">; Trumpet</span>
  <span class="comment">; INITIALIZATION</span>
         <span class="opc">mididefault</span>   60, p3 <span class="comment">; Default duration of 60 -- overridden by score.</span>
         <span class="opc">midinoteonkey</span> p4, p5 <span class="comment">; Channels MIDI input to pfields.</span>
  <span class="comment">; Use channel assigned in fluidload.</span>
  ichannel   <span class="op">=</span> 3
  ikey       <span class="op">=</span> p4
  ivelocity  <span class="op">=</span> p5
         <span class="opc">fluidNote</span> gienginenum2, ichannel, ikey, ivelocity
<span class="oblock">endin</span>

<span class="comment">; COLLECT AUDIO FROM ALL SOUNDFONTS</span>

<span class="oblock">instr</span> 100 <span class="comment">; Fluidsynth output</span>

  iamplitude1 <span class="op">=</span> 7
  iamplitude2 <span class="op">=</span> 7

<span class="comment">; AUDIO</span>
aleft1, aright1 <span class="opc">fluidOut</span>   gienginenum1
aleft2, aright2 <span class="opc">fluidOut</span>   gienginenum2
                <span class="opc">outs</span>       (aleft1 <span class="op">*</span> iamplitude1) <span class="op">+</span> (aleft2 <span class="op">*</span> iamplitude2),  \
                           (aright1 <span class="op">*</span> iamplitude1) <span class="op">+</span> (aright2 <span class="op">*</span> iamplitude2)
<span class="oblock">endin</span>
<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>

<span class="stamnt">i</span> 1 0 3  60  100
<span class="stamnt">i</span> 2 1 3  60  100
<span class="stamnt">i</span> 3 3 3  63  100
<span class="stamnt">i</span> 100 0 10		<span class="comment">;run for 10 seconds </span>
<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
      </div>
      <div class="refsect1">
        <a id="idp108718736"></a>
        <h2>See Also</h2>
        <p><a class="link" href="fluidNote.html" title="fluidNote"><em class="citetitle">fluidNote</em></a>, <a class="link" href="fluidLoad.html" title="fluidLoad"><em class="citetitle">fluidLoad</em></a></p>
        <p> More information on soundfonts in the Floss Manuals: <a class="ulink" href="http://en.flossmanuals.net/csound/ch048_d-reading-midi-files" target="_top"><em class="citetitle">http://en.flossmanuals.net/csound/ch048_d-reading-midi-files</em></a></p>
        <p> Other information on soundfonts on Wikipedia: <a class="ulink" href="http://en.wikipedia.org/wiki/Soundfont" target="_top"><em class="citetitle">http://en.wikipedia.org/wiki/Soundfont</em></a></p>
      </div>
      <div class="refsect1">
        <a id="idp108723904"></a>
        <h2>Credits</h2>
        <p>Michael Gogins (gogins at pipeline dot com), Steven Yi. 
      Thanks to Peter Hanappe for Fluidsynth.</p>
        <p>Optional <span class="emphasis"><em>iNumChannels</em></span> and <span class="emphasis"><em>iPolyphony</em></span> parameters added in 5.07</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="fluidControl.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="fluidLoad.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">fluidControl </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> fluidLoad</td>
        </tr>
      </table>
    </div>
  </body>
</html>
